<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@taglib prefix="s" uri="strutsTags"%>
<%@taglib prefix="ty" uri="/wyzzTags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<head>
	<base href="<%=basePath%>">
	<s:head />
	<title>考勤机用户同步</title>
	<jsp:include flush="true" page="/sitemesh/jsPackage.jsp"></jsp:include>
	<link href="resource/css/style.css" rel="stylesheet" type="text/css" />
	<script type='text/javascript' src='dwr/interface/DwrForAttend.js'></script>
	<script type='text/javascript'
		src='dwr/interface/DwrSyncAttdMachine.js'></script>
</head>
<body onload="hrm.common.check_order();">
	<span class="errorMessage" id="message"></span>
	<s:component template="bodyhead">
		<s:param name="pagetitle" value="'考勤机用户同步'" />
	</s:component>
	<form id="attdSyncRecordShow" name="attdSyncRecordShow"
		action="attdSyncRecordShow.action" namespace="/examin" method="POST">
		<table width="100%" class="formtable">
			<tr>
				<td>
					<!-- 隐藏字段 -->
					<s:hidden name="asrId"></s:hidden>
					<s:hidden id="order" name="page.order" />
					<s:hidden id="operate" name="page.operate" />
					<s:hidden id="page.currentPage" name="page.currentPage" />
					<table width="100%">
						<tr>
							<td align="right">
								员工:
							</td>
							<td>
								<s:textfield id="record.asrEmp.empName"
									name="record.asrEmp.empName" size="16" maxlength="64" />
							</td>
							<td align="right">
								组织单元:
							</td>
							<td>
								<s:orgselector id="orgselector1"
									name="record.asrEmp.empDeptNo.departmentName"
									hiddenFieldName="record.asrEmp.empDeptNo.id" />
							</td>
							<td align="right">
								工作地区:
							</td>
							<td>
								<s:select name="record.asrEmp.empLocationNo.id" list="locations"
									listKey="id" listValue="locationName" multiple="false"
									emptyOption="true" size="1" />
							</td>
							<td align="right">
								员工状态:
							</td>
							<td>
								<s:select name="record.asrEmp.empStatus"
									value="record.asrEmp.empStatus" list="#{2:'全部',0:'离职',1:'在职'}"
									emptyOption="false" />
							</td>
						</tr>
						<tr>
							<td align="right">
								考勤卡号:
							</td>
							<td>
								<s:textfield id="record.asrEmpCardNo" name="record.asrEmpCardNo"
									size="16" maxlength="10" />
							</td>
							<td align="right">
								登记号码:
							</td>
							<td>
								<s:textfield name="startEmpCardNo" size="8" maxlength="10" />
								到
								<s:textfield name="endEmpCardNo" size="8" maxlength="10" />
							</td>
							<td align="right">
								考勤机:
							</td>
							<td>
								<s:select name="record.asrAttdMachine.macId" list="machineList"
									listKey="macId" listValue="macNo" multiple="false"
									emptyOption="true" size="1" />
							</td>
							<td align="right">
								权限/同步:
							</td>
							<td>
								<s:select id="asrAuthLevel" name="record.asrAuthLevel"
									value="record.asrAuthLevel" list="#{2:'全部',0:'普通员工',1:'管理员'}"
									emptyOption="false" />
								<s:select id="sync" name="record.asrSync" value="record.asrSync"
									list="#{2:'全部',0:'否',1:'是'}" emptyOption="false" />
							</td>
						</tr>
					</table>
				</td>
				<td>
					<input title="[Alt+F]" accesskey="F" name="sub_button"
						class="button" type="button" value="查询" onclick="searchData();" />
					<input title="[Alt+C]" accesskey="C" name="clear_button"
						class="button" type="button"
						onClick="window.location='attdSyncRecordShow.action';" value="重置">
				</td>
			</tr>
		</table>

		<!-- 操作 -->
		<div class="operatediv">
			<span class="operatedivleft"> <input type="hidden"
					name="searchOrExport" id="searchOrExport" /> <s:hidden
					id="output-ommId" name="outmatchModelId" /> <s:hidden
					id="output-ioName" name="outputIoName" /> <ty:auth
					auths="401,3 or 401,2">
					<input class="button" type="button" value="更新同步记录"
						onclick="empSelecotr('syncToMachine');" />
					<input class="button" type="button" value="删除同步记录"
						onclick="batchDelete();" />
					<input class="button" type="button" value="同步记录检查"
						onclick="empSelecotr('syncToSystem');" />
					<input id="btnOutput" class="button" type="button" value="同步记录导出"
						onclick="exportBatchData();" />
					<input class="button" type="button" value="指纹拷贝"
						onclick="copyfinger();" />
				</ty:auth> </span>
			<span class="operatedivright">本次查询共得到<s:property
					value="page.totalRows" />条考勤机同步记录</span>
		</div>

		<table id="dataTable" cellpadding="0" cellspacing="0" width="100%"
			border="0" class="gridtableList">
			<tr>
				<th>
					<input id='checkall' name='checkall' class="checkbox"
						type="checkbox"
						onclick="hrm.common.checkAllByName('changIds','checkall');">
				</th>
				<th>
					<a href="#"
						onclick="hrm.common.order_submit('emp.empDistinctNo','attdSyncRecordShow');">员工编号</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='emp.empDistinctNo_img'>
				</th>
				<th>
					<a href="#"
						onclick="hrm.common.order_submit('emp.empName','attdSyncRecordShow');">姓名</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='emp.empName_img'>
				</th>
				<th>
					<a href="#"
						onclick="hrm.common.order_submit('emp.empDeptNo','attdSyncRecordShow');">部门</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='emp.empDeptNo_img'>
				</th>
				<th>
					<a href="#"
						onclick="hrm.common.order_submit('emp.empStatus','attdSyncRecordShow');">状态</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='emp.empStatus_img'>
				</th>
				<th>
					<a href="#"
						onclick="hrm.common.order_submit('asrAttdMachine.macNo','attdSyncRecordShow');">考勤机号</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='asrAttdMachine.macNo_img'>
				</th>
				<th>
					<a href="#"
						onclick="hrm.common.order_submit('asrEmpMachineNo','attdSyncRecordShow');">登记号码</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='asrEmpMachineNo_img'>
				</th>
				<th>
					<a href="#"
						onclick="hrm.common.order_submit('asrEmpCardNo','attdSyncRecordShow');">考勤卡号</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='asrEmpCardNo_img'>
				</th>
				<th>
					<a href="#"
						onclick="hrm.common.order_submit('asrAuthLevel','attdSyncRecordShow');">权限</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='asrAuthLevel_img'>
				</th>
				<th>
					<a href="#"
						onclick="hrm.common.order_submit('asrSync','attdSyncRecordShow');">同步</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='asrSync_img'>
				</th>
				<th>
					操作
				</th>
			</tr>
			<s:if test="!attdSyncRecordList.isEmpty()">
				<!--判断是否为空-->
				<s:iterator value="attdSyncRecordList" status="st">
					<tr>
						<td align="center">
							<input type="checkbox" name='changIds' class="checkbox"
								value="<s:property value='asrId'/>" />
							<input type="hidden" id="hasFinger<s:property value='asrId'/>"
								value="<s:property value='asrAttdMachine.macHasFinger'/>" />
							<input type="hidden" id="macNo<s:property value='asrId'/>"
								value="<s:property value='asrAttdMachine.macNo'/>" />
						</td>
						<td id="srcEmpDistinctNo<s:property value="#st.count"/>"
							align="center">
							&nbsp;
							<s:property value="asrEmp.empDistinctNo" />
						</td>
						<td id="asrEmpName<s:property value="#st.count"/>" align="center">
							&nbsp;
							<s:property value="asrEmp.empName" />
						</td>
						<td id="asrEmpDept<s:property value="#st.count"/>" align="center">
							&nbsp;
							<s:property value="asrEmp.empDeptNo.departmentName" />
						</td>
						<td id="asrEmpStatus<s:property value="#st.count"/>"
							align="center">
							&nbsp;
							<s:if test="asrEmp.empStatus == 0">离职</s:if>
							<s:if test="asrEmp.empStatus == 1">在职</s:if>
						</td>
						<td id="asrAttdMachineNo<s:property value="#st.count"/>"
							align="center">
							&nbsp;
							<s:property value="asrAttdMachine.macNo" />
						</td>
						<td id="asrEmpMachineNo<s:property value="#st.count"/>"
							align="center">
							&nbsp;
							<s:property value="asrEmpMachineNo" />
						</td>
						<td id="asrEmpCardNo<s:property value="#st.count"/>"
							align="center">
							&nbsp;
							<s:property value="asrEmpCardNo" />
						</td>
						<td id="asrAuthLevel<s:property value="#st.count"/>"
							align="center">
							&nbsp;
							<s:if test="asrAuthLevel == 0">普通员工</s:if>
							<s:if test="asrAuthLevel == 1">管理员</s:if>
						</td>
						<td id="asrSync<s:property value="#st.count"/>" align="center">
							&nbsp;
							<s:if test="asrSync==1">是</s:if>
							<s:if test="asrSync==0">否</s:if>
						</td>
						<td align="center">
							<s:if test="asrEmp != null">
								<img
									onclick="singleSysToMachine('<s:property value="asrEmp.id"/>','<s:property value="asrEmp.empName"/>','<s:property value="asrEmpMachineNo"/>','<s:property value="asrEmpCardNo"/>','<s:property value="asrAttdMachine.macId"/>','<s:property value="asrAttdMachine.macNo"/>','<s:property value="asrAuthLevel"/>');"
									alt="更新同步记录" title="更新同步记录" class="urlimg"
									src="resource/images/WorkflowSequence.gif">
							</s:if>
							<img onclick="deleteRecord('<s:property value="asrId"/>');"
								alt="删除" title="删除" class="urlimg"
								src="resource/images/deletesalaryconf.gif">
						</td>
					</tr>
				</s:iterator>
			</s:if>
			<s:else>
				<tr>
					<td align="center" colspan="17">
						无符合条件的考勤机同步记录！
					</td>
				</tr>
			</s:else>
		</table>
		<s:pager end="page.end" pageNo="page.currentPage"
			totalRows="page.totalRows" totalPages="page.totalPages"
			formId="attdSyncRecordShow" start="page.start" />
	</form>
	<div id="tmpletId" style="DISPLAY: none">
		<img src="resource/images/basic_search.gif"
			onload="hrm.common.check_order();" />
		<!--改为调用common中方法-->
	</div>

	<div id="dlgEmpListDiv" title="用户选择列表">
		<jsp:include flush="true" page="../examin/attdOperate.jsp"></jsp:include>
	</div>
	<script type="text/javascript" language="javascript">
	//查询方法(点击查询按钮)
	function searchData() {
		document.getElementById("searchOrExport").value = "";
		document.forms[0].submit();//提交表单
	}

	//敲击键盘事件
	function enterDown(event) {
		event = event ? event : (window.event ? window.event : null);
		if (event != null && event.keyCode == 13) {
			return;
		}
	}

	hrm.common.initDialog('dlgEmpListDiv', 480);
	hrm.common.initDialog('dlgSyncSingleUser', 400);
	hrm.common.initDialog('dlgCopyFinger', 480);

	$('#attdDate').val(hrm.common.getCurrentDate()); //给attdDate赋上当天日期

	function empSelecotr(operate) {
		switchOperate(operate);
		hrm.common.openDialog('dlgEmpListDiv');
	}

	// 单个员工同步弹出框；
	function singleSysToMachine(empId, empName, empMachineNo, empCardNo,
			machineId, machineNo, userType) {
		document.getElementById("singleEmpId").value = empId;
		document.getElementById("singleMacId").value = machineId;
		if (userType == 0)
			document.getElementById("singleuserType0").checked = true;
		else
			document.getElementById("singleuserType1").checked = true;
		document.getElementById("singleUserPass").value = "";

		document.getElementById("td_empManchineNo").innerHTML = empMachineNo;
		document.getElementById("td_empCardNo").innerHTML = empCardNo;
		$("#dlgSyncSingleUser").dialog("option", "title",
				"将" + empName + "同步到考勤机" + machineNo);
		hrm.common.openDialog('dlgSyncSingleUser');
	}

	function sysToMachine() {
		hrm.common.closeDialog("dlgSyncSingleUser");
		$('#divWait').show();

		var empId = document.getElementById("singleEmpId").value;
		var machineNo = document.getElementById("singleMacId").value;
		var radio = document.getElementsByName('singleuserType');
		var userType = 0;
		for ( var i = 0; i < radio.length; i++) {
			if (radio[i].checked)
				userType = radio[i].value;
		}
		var password = document.getElementById("singleUserPass").value;

		DwrSyncAttdMachine.syncToMachine(empId, machineNo, userType, password,
				callback);
		function callback(data) {
			$('#divWait').hide();
			showReturnInfo(data);
		}
	}

	function deleteRecord(recordId) {
		if (recordId == null || recordId.trim().length == 0) {
			alert("数据错误，请刷新后重试！");
			return;
		}
		if (!confirm("您确定要删除该条同步记录吗？"))
			return;

		$('#divWait').show();
		DwrSyncAttdMachine.batchDelete(recordId, callback);
		function callback(data) {
			$('#divWait').hide();
			showReturnInfo(data);
		}
	}

	// 指纹拷贝；
	function copyfinger() {
		var arr = document.getElementsByName("changIds");
		var asrIds = "";
		var currentMacNo = "";
		for ( var i = 0; i < arr.length; i++) {
			if (arr[i].checked) {
				var hasFinger = document.getElementById("hasFinger"
						+ arr[i].value).value;
				var tempMacNo = document.getElementById("macNo" + arr[i].value).value;
				if (currentMacNo != "" && tempMacNo != currentMacNo) {
					alert("选中的员工必须在同一台考勤机上，请重新选择！");
					return;
				}
				if (hasFinger != 1) {
					alert("只能选择指纹机同步记录！");
					return;
				}

				currentMacNo = tempMacNo;
				asrIds += arr[i].value + ",";
			}
		}
		if (asrIds.length == 0) {
			alert("请至少选择一条记录！");
			return;
		}
		asrIds = asrIds.substring(0, asrIds.length - 1);
		document.getElementById("copyfinger_asrIds").value = asrIds;

		// 检查系统中是否有指纹考勤机；
		var arr = document.getElementsByName("copyfinger_machineNo");
		if (arr == null || arr.length == 0) {
			alert("您没有配置指纹考勤机！");
			return;
		}

		document.getElementById("TD_fromManchine").innerHTML = currentMacNo;
		$("#dlgCopyFinger").dialog("option", "title", "指纹拷贝");
		hrm.common.openDialog('dlgCopyFinger');
	}

	function copyToMachine() {
		var arr = document.getElementsByName("copyfinger_machineNo");
		if (arr == null) {
			alert("请先选择目的考勤机！");
			return;
		}

		var macIds = "";
		for ( var i = 0; i < arr.length; i++) {
			if (arr[i].checked)
				macIds += arr[i].value + ",";
		}
		macIds = macIds.substring(0, macIds.length - 1);
		if (macIds.length == 0) {
			alert("请选择目的考勤机！");
			return;
		}

		hrm.common.closeDialog("dlgCopyFinger");
		$('#divWait').show();
		var asrIds = document.getElementById("copyfinger_asrIds").value;
		DwrSyncAttdMachine
				.copyUserFingerToMachine(asrIds, macIds, copyCallback);
		function copyCallback(data) {
			$('#divWait').hide();
			showReturnInfo(data);
		}
	}

	// 数据导出
	function exportBatchData() {
		document.getElementById("searchOrExport").value = "export";
		document.forms[0].submit();
	}
</script>
	<jsp:include flush="true" page="../io/div_upload.jsp"></jsp:include>
	<jsp:include flush="true" page="../io/div_omm_select.jsp"></jsp:include>
	<jsp:include page="../sitemesh/div_wait.jsp" flush="true"></jsp:include>
</body>
